import 'dart:io';

import 'package:chatgreat/helper/color.dart';
import 'package:chatgreat/helper/my_widget.dart';
import 'package:chatgreat/page/component/background_container.dart';
import 'package:chatgreat/page/component/sliver_component.dart';
import 'package:chatgreat/page/component/theme/custom_size.dart';
import 'package:chatgreat/page/component/theme/custom_theme.dart';
import 'package:chatgreat/repo/settings_repo.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
// import 'package:stripe_js/stripe_js.dart';

import '../../../repo/api_server.dart';
import '../../helper/upload.dart';
import '../component/dialog.dart';
import '../component/enhanced_textfield.dart';

class SignoutScreen extends StatefulWidget {
  final SettingRepository setting;

  const SignoutScreen(
      {super.key, required this.setting,});

  @override
  State<SignoutScreen> createState() => _SignoutScreenState();
}

enum GenerateStatus { display, generating, over }

class _SignoutScreenState extends State<SignoutScreen> {

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final customColors = Theme.of(context).extension<CustomColors>()!;
    return BackgroundContainer(
      setting: widget.setting,
      child: Container(
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage('images/bg1.png'),
            fit: BoxFit.fill,
          ),
        ),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          body: _buildFeedbackWidget(customColors),
        ),
      ),
    );
  }

  /// 反馈问题
  Widget _buildFeedbackWidget(
      CustomColors customColors,
      ) {
    return SliverCreateComponent(
      title: const Text(
        "注销账号",
        style: TextStyle(
          fontSize: CustomSize.appBarTitleSize,
          color: Colors.white,
        ),
      ),
      leading: IconButton(
        icon: Icon(
          Icons.arrow_back,
          color: customColors.weakLinkColor,
        ),
        onPressed: () {
          if (context.canPop()) {
            context.pop();
          }
        },
      ),
      child: Column(
        children: [
          Expanded(
            child: ListView(
              padding: const EdgeInsets.symmetric(horizontal: 22, vertical: 22),
              shrinkWrap: true,
              children: [
                imgWidget(51.5, 51.5, 'waring_tips_icon'),
                const SizedBox(height: 32),
                MyTextWeight('账号注销后不可恢复，您将失去所有账号权益，已充值会员和购买内容无法恢复，请确认您是否需要注销！', 15, Colors.white, FontWeight.w500),
              ],
            ),
          ),
          MyTextWeight('您将永久失去您当前的账号!', 15, Colors.white, FontWeight.w500),
          Container(
            margin: const EdgeInsets.only(left: 19, right: 19, bottom: 67, top: 38),
            width: double.infinity,
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/guide_button.png'),
                fit: BoxFit.fill,
              ),
            ),
            child: TextButton(
              child: MyTextWeight('确认注销', 16, Colors.white, FontWeight.normal),
              onPressed: () async {

                EasyLoading.show(status: '请稍等...');
                APIServer().logoff().then((value) {
                  EasyLoading.dismiss();
                  context.go('/login');
                }).catchError((e) {
                  EasyLoading.dismiss();
                });
              },
            ),
          ),
        ],
      ),
    );
  }

}
